from fastapi import FastAPI
from flask import Flask, request, jsonify
import os
import uvicorn
from fetch_data_main import *
from postImage_check import *
from postContent_check import *
from brandcategory import *
from pydantic import BaseModel
UPLOAD_FOLDER = 'uploads'
os.makedirs(UPLOAD_FOLDER, exist_ok=True)

app = FastAPI()
class Item(BaseModel):
    content: str = None
    title: str = None

@app.post("/imagecheck")
async def image_check(item: Item):
    item_dict = item.dict()
    if item.content:
        image_path=item.content
        imageCheck_rs=imageCheck(image_path)
        return imageCheck_rs
    return None

@app.post("/contentcheck")
async def content_check(item: Item):
    item_dict = item.dict()
    if item.content:
        content_text=item.content
        contentCheck_rs=contentCheck(content_text)
        return contentCheck_rs
    return None

@app.post("/ischatgpt")
async def read_root(item: Item):
    item_dict = item.dict()
    if item.content:
        text=item.content
        t=GPT_promote(text)
        if t=='是':
            return {"code":"1"}
        else:
            return {"code":"2"}
    return {"message": "2"}
@app.post("/brandcategory")
async def brand_category(item: Item):
    item_dict = item.dict()
    if item.title:
        text=item.title
        print(text)
        t=predict_category_and_brand(text)
        return t;
    return None
if __name__ == "__main__":

    uvicorn.run("main:app", host="0.0.0.0", port=50627, reload=True)
